﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="../common/jquery.cookie.js"></script>
    <script src="../common/common.js"></script>
    <script src="js/core.js"></script>
    <script>
        $(function () {
            var wrapper = $('#wrapper');

            var contactForm = new CompositeForm('contact-form', 'POST', 'demo.html');

            var nameFieldset = new CompositeFieldset('name-fieldset');
            nameFieldset.add(new InputField('first-name', 'First Name'));
            nameFieldset.add(new InputField('last-name', 'Last Name'));
            contactForm.add(nameFieldset);

            var addressFieldset = new CompositeFieldset('address-fieldset');
            addressFieldset.add(new InputField('address', 'Address'));
            addressFieldset.add(new InputField('city', 'Last Name'));
            addressFieldset.add(new SelectField('state', 'State', [{ name: 'Beijing' }, { name: 'Shanghai' }]));
            contactForm.add(addressFieldset);

            contactForm.add(new TextareaField('comments', 'Comments'));
            wrapper.append(contactForm.getElement());

            //addEvent(window, 'unload', contactForm.save);
            //addEvent(window, 'load', contactForm.restore);

            //addEvent(document.getElementById('save-button'), 'click', contactForm.save);
            //addEvent(document.getElementById('restore-button'), 'click', contactForm.restore);

            $(window).load(function () { contactForm.restore(); });
            $(window).unload(function () { contactForm.save(); });
            $('#save-button').click(function () { contactForm.save(); });
            $('#restore-button').click(function () { contactForm.restore(); });

            //function Shape() {
            //    this.name = "Generic";
            //    this.draw = function () {
            //        return "Drawing " + this.name + " Shape";
            //    };
            //}

            //(function welcomeMessage() {
            //    var shape1 = new Shape();
            //    //alert(shape1.draw());
            //    alert(shape1.hasOwnProperty("name"));  //this is returning false
            //})();
        });
    </script>
</head>
<body>
    <div id="wrapper">

    </div>
    <a id="save-button">Save</a>
    <a id="restore-button">Restore</a>
</body>
</html>
